package com.example.myapplication.utils;


import android.content.Context;
import android.content.SharedPreferences;

import com.example.myapplication.WordApp;

//单例模式
public class Preference {

    private static final String KEY_WORD_DB = "KEY_WORD_DB";
    private static final String KEY_IDX_START = "KEY_IDX_START";
    private static final String KEY_IDX_END = "KEY_IDX_END";
    private static final String KEY_ORDER = "KEY_ORDER";

    private static Preference mInstance;


    private SharedPreferences cache;


    private Preference() {
        cache = WordApp.AppContext.getSharedPreferences(
                "local", Context.MODE_PRIVATE);
    }

    public static Preference getInstance() {
        if(mInstance == null) {
            mInstance = new Preference();
        }
        return mInstance;
    }

    public void setWordDB(String db) {
        cache.edit().putString(KEY_WORD_DB, db).apply();
    }

    public String getWordDB() {
        return cache.getString(KEY_WORD_DB,"CET6");
    }

    public void setIdxStart(int idx) {
        cache.edit().putInt(KEY_IDX_START, idx).apply();
    }
    public void setIdxEnd(int idx) {
        cache.edit().putInt(KEY_IDX_END, idx).apply();
    }


    public int getIdxStart() {
        return cache.getInt(KEY_IDX_START,1);
    }

    public int getIdxEnd() {
        return cache.getInt(KEY_IDX_END,1);
    }

    public void setWordOrder(int i) {
        cache.edit().putInt(KEY_ORDER, i).apply();
    }

    public int getWordOrder() {
        return cache.getInt(KEY_ORDER,1);
    }

}
